package  
{
	import Box2D.Common.Math.b2Vec2;
	import Box2D.Dynamics.b2Body;
	import flash.geom.Rectangle;
	/**
	 * ...
	 * @author hbb
	 */
	public class Player extends BaseObject implements ITickedObject 
	{
		private var vx:Number = 2;
		
		private var vy:Number = 0;
		
		public function Player() 
		{
			width = 30;
			height = width; // player is circle
			typeShape = 'circle';
			b2_bodyDef.type = b2Body.b2_dynamicBody;
		}
		
		override public function hitTest(a_x:Number, a_y:Number):Boolean 
		{
			var pos:b2Vec2 = b2_body.GetPosition();
			var x:Number = pos.x * World.PIXELS_TO_METRE - width * .5;
			var y:Number = pos.y * World.PIXELS_TO_METRE - height * .5;
			var rect:Rectangle = new Rectangle( x - 10, y - 10, width + 20, height + 20 );
			return rect.contains( a_x, a_y );
		}
		
		
		public function onTick():void
		{
			var v:b2Vec2 = b2_body.GetLinearVelocity();
			v.x = vx;
			v.y = vy || v.y;
			
			b2_body.SetLinearVelocity( v );
		}
		
		public function riseOrFall():void
		{
			if ( 0 == vy )
			{
				vy = -2;
			}
			else
			{
				vy = 0;
			}
		}
		
		public function turnAround():void
		{
			vx = -vx;
		}
		
	}

}